/**
 * 
 */
package uk.co.altv.simpledb.operation;

import uk.co.altv.simpledb.Connection;
import uk.co.altv.simpledb.filter.DomainFilter;

/**
 * @author niki
 *
 */
public class Select extends Operation{

	private DomainFilter filter = null;
	private String selectExpression;
	private String nextToken = "";
	private boolean consistentRead = false;
	
	public Select(String selectExpression) {
		this(selectExpression,null);
	}
	public Select(String selectExpression, boolean consistentRead) {
		this(selectExpression,null);
		this.consistentRead = consistentRead;
	}
	/**
	 */
	public Select(String selectExpression, DomainFilter filter) {
		this.selectExpression = selectExpression;
		this.filter = filter;
		this.action = "Select";
	}
	public String prepareStatement(Connection endpoint) {
		String statement = getIdAndAction(endpoint);
		if(consistentRead) { statement += appendData(Key.CONSISTENT_READ, "true", endpoint); }
		statement += appendData(Key.NEXT_TOKEN, this.nextToken, endpoint)
						+ appendData(Key.SELECT_EXPRESSION, this.selectExpression, endpoint)
						+ doTail(endpoint);
		return statement + appendData(Key.SIGNATURE, endpoint.sign(statement), endpoint);
	}
	/**
	 * @param nextToken the nextToken to set
	 */
	public void setNextToken(String nextToken) {
		this.nextToken = nextToken;
	}
	/**
	 * @return the nextToken
	 */
	public String getNextToken() {
		return nextToken;
	}
	/**
	 * @return the filter
	 */
	public DomainFilter getFilter() {
		return filter;
	}
	/**
	 * @param filter the filter to set
	 */
	public void setFilter(DomainFilter filter) {
		this.filter = filter;
	}

}
